package com.example.hospital.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.hospital.pojo.*;
import com.example.hospital.service.IRsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Api(tags = "RsController")
@RestController
@RequestMapping("/Rs")
public class RsController {
    @Autowired
    private IRsService iRsService;
    @ApiOperation(value = "为病人添加症状标签")
    @PostMapping("/")
    public RespBean addBasic(@RequestBody Rs rs){
        LocalDate endDate = rs.getEndDate();
        rs.setEndDate(endDate);
        rs.setCreateDate(LocalDate.now());
        if(iRsService.save(rs)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @ApiOperation(value = "删除病人症状信息标签")
    @DeleteMapping("/{id}")
    public RespBean deleteByid(@PathVariable Integer id){
        if(iRsService.removeById(id)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

    @ApiOperation(value = "删除病人症状信息标签")
    @DeleteMapping("/delete")
    public RespBean deleteByid(@RequestBody RsVO rsVO){
        int id = rsVO.getId();
        int sid = rsVO.getSid();
        LambdaQueryWrapper<Rs> lam = new LambdaQueryWrapper<>();
        lam.eq(Rs::getPid,id).eq(Rs::getSid,sid);
        if(iRsService.remove(lam)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

}
